CROSS_COMPILE	= arm-none-linux-gnueabi-
CC		= $(CROSS_COMPILE)gcc
LD		= $(CROSS_COMPILE)ld
AR		= $(CROSS_COMPILE)ar
OBJCOPY		= $(CROSS_COMPILE)objcopy
OBJDUMP		= $(CROSS_COMPILE)objdump

LDSCRIPT	= ./s3c24x0/ucos_ii.lds 
TEXTBASE	= 0x30000000

INCLUDE		= -I. -I./s3c24x0/ -I./lib
CFLAGS		= -Wall -Werror -fno-builtin -march=armv4t $(INCLUDE) -O0
LDFLAGS 	= -T $(LDSCRIPT) -Ttext $(TEXTBASE) \
          	  -Bstatic \
          	  -nostdlib \
          	  --no-undefined \
          	  --defsym raise=hang \
#          	  --defsym putchar=putc

LIBS		= -L/home/sean/openmoko/toolchain/sourcery/arm-2008q3/lib/gcc/arm-none-linux-gnueabi/4.3.2 \
		  -lgcc

OSIMAGE		= ucosii-dma2440xp

KSRCS		= ./ucos_ii.c	\
		  ./os_cpu_c.c

KSRCS_S		= ./os_cpu_s.S

BSRCS		= ./s3c24x0/main.c \
		  ./s3c24x0/serial.c \
		  ./s3c24x0/speed.c \
		  ./s3c24x0/irq_s3c24x0.c \
		  ./s3c24x0/irq.c \
		  ./s3c24x0/timer.c

BSRCS_S		= ./s3c24x0/start.S

LSRCS		= ./lib/console.c \
		  ./lib/vsprintf.c \
		  ./lib/string.c \
		  ./lib/ctype.c

KOBJS		= $(KSRCS:.c=.o)
KOBJS_S		= $(KSRCS_S:.S=.o)
BOBJS		= $(BSRCS:.c=.o)
BOBJS_S		= $(BSRCS_S:.S=.o)
LOBJS		= $(LSRCS:.c=.o)

OBJS		= $(KOBJS) $(KOBJS_S) $(BOBJS) $(BOBJS_S) $(LOBJS)

$(KOBJS) : %.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@
$(KOBJS_S) : %.o : %.S
	$(CC) -c $(CFLAGS) $< -o $@
$(BOBJS) : %.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@
$(BOBJS_S) : %.o : %.S
	$(CC) -c -DTEXT_BASE=$(TEXTBASE) $(CFLAGS) $< -o $@
$(LOBJS) : %.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

all: $(OBJS)
	$(LD) $(LDFLAGS) -o $(OSIMAGE).elf $(OBJS) $(LIBS)
	$(OBJDUMP) -D $(OSIMAGE).elf > $(OSIMAGE).objdump
	$(OBJCOPY) --gap-fill=0xff -O binary $(OSIMAGE).elf $(OSIMAGE).bin
	rm -rf $(OBJS) 

clean:
	rm -rf $(OBJS) $(OSIMAGE).elf $(OSIMAGE).objdump $(OSIMAGE).bin
	rm -rf *~
